import std.stdio;
import nkf;

version (Win32)
{

pragma(lib, "..\\win32\\nkf_d.lib");

}

enum string USAGE = 
"Usage: %s option infile [outfile]"
    ;

int main(string[] args)
{
    if (args.length < 3)
    {
        writefln(USAGE, args[0]);
        return -1;
    }
    
    auto option = args[1];
    auto infile = File(args[2], "r");
    
    void process(ref File dst)
    {
        auto buf = new char[500];
        
        while (!infile.eof)
        {
            auto sz = infile.readln(buf);
            dst.write(nkf.nkf(option, buf));
        }
    }
    
    if (args.length < 4)
    {
        process(stdout);
    }
    else
    {
        auto outfile = File(args[3], "w");
        
        process(outfile);
        
        outfile.close();
    }
    
    return 0;
}
